//
//  SettingsViewController.m
//  PlotMate
//
//  Created by Brian Boyle on 19/04/2012.
//  Copyright (c) 2012 Brian Boyle. All rights reserved.
//

#import "SettingsViewController.h"

@implementation SettingsViewController
@synthesize metricSwitch = _metricSwitch;
@synthesize metricLabel = _metricLabel;



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    //Set the font of the metric label
    [self.metricLabel setFont:[UIFont fontWithName:@"Sketch Rockwell" size:20]];
    self.metricLabel.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
    self.metricLabel.shadowColor = [UIColor blackColor];
    self.metricLabel.shadowOffset = CGSizeMake(1, 1);
   
    //Set the unit of measurement from user preferences
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    BOOL useMetric = [prefs boolForKey:@"metric"];
    [self.metricSwitch setOn:useMetric];
}


- (void)viewDidUnload
{
    [self setMetricLabel:nil];
    [self setMetricSwitch:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

/*Change the metric value based on teh swtich value*/
- (IBAction)switchValueChanged:(UISwitch *)sender 
{
     NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    if(sender.on){
        [sender setOn:YES];
        [prefs setBool:YES forKey:@"metric"];
    }else{
        [sender setOn:NO];
        [prefs setBool:NO forKey:@"metric"];
    }
}
@end
